package cn.itcast.itcaststore.web.filter;

import cn.itcast.itcaststore.dao.Impl.IProductDao;
import cn.itcast.itcaststore.domain.Notice;
import cn.itcast.itcaststore.service.Impl.INoticeService;
import cn.itcast.itcaststore.service.Impl.IProductService;
import cn.itcast.itcaststore.service.NoticeService;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.util.List;

@WebFilter("/client/index.jsp")
public class IndexFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {

        NoticeService noticeService=new INoticeService();
        IProductService iProductService = new IProductService();

        List noticeList=noticeService.getNoticeList();
        List productList = iProductService.getListProduct("全部商品", 1, 2);

        request.setAttribute("pList", productList);
        request.setAttribute("noticeList", noticeList);
        request.getRequestDispatcher("/client/index.jsp");

        chain.doFilter(request, response);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
